@extends('layouts.console_header')

@section('title', '红包管理')

@section('resources')
    @parent
	<style>
		.details1_name table{border-color: #eee;margin-top: 20px;}
		.red_intercalate{cursor: pointer;}
		.red_intercalate_value{position: fixed;top: 200px;left: 50%;width: 500px;margin-left: -250px;border-radius: 5px;box-shadow: 0px 0px 5px 5px rgba(128,128,128,0.5);background-color: #fff;display: none;}
		.red_intercalate_value .title{text-align: center;margin: 10px 0;font-size: 20px;}
		.red_intercalate_value img{position: absolute;top: 10px;right: 10px;width: 30px;height: 30px;}
		.red_intercalate_value .content{margin: 10px 40px;}
		.red_intercalate_value .content input{border: 1px solid #000;padding: 5px;height: 15px;}
		#red_intercalate_cancel{background-color: #999;width: 100px;height: 30px;border-radius: 5px;margin-left: 20px;color: #fff;}
		#red_intercalate_sure{background-color: #9955c6;width: 100px;height: 30px;border-radius: 5px;margin-right: 20px;color: #fff;}
		.red_envelope_title{text-align: center;height: 30px;background-color: #eee;padding: 25px 0;}
		.red_envelope_title p{width: 210px;overflow: hidden;margin: 0 auto;height: 30px;}
		.red_envelope_title p span{float: left;border: 1px solid #333;width: 103px;height: 28px;line-height: 28px;cursor: pointer;}
		.details2 ul{padding-top: 10px;}
		.details2 ul .red_envelope_count{text-align: center;font-size: 20px;margin: 15px 0;}
		.details2 ul .red_envelope_list{text-align: center;border-color: #eee;}
		.details2 ul .red_envelope_list td{padding: 5px;}
		.details2 ul .title{margin: 20px 0 20px 10px;border-left: 3px solid #9955c6;padding-left: 8px;}
		.details2 ul .set_up{text-align: center;margin: 17px 30px 0 0;font-size: 16px;padding: 5px;background-color: #9955c6;border-radius: 5px;}
		.historic_records{margin: 20px 0;color: #9955c6;display: inline-block;}
	</style>
@endsection

@section('content')
<section class="user_list">
	<div style="border-bottom: 2px solid #9955c6;overflow: hidden;">
		<p class="fz_14 account_title fl" style="border: none;">
		    <span style="color: #7f7f7f;"><a href="/console/index">首页</a>>用户版运营></span>
		    <span class="co_violet">红包管理</span>
        </p>
		<a onclick="history.go(-1);" href="#"><p class="fr tc back_btn">返回</p></a>
	</div>
	<div class="details1">
		<p>订单红包</p>
		<span style="margin-left: 23px;">订单红包为无使用金额与品类限制的红包，订单红包金额低于1.0时不发给用户，最低为1.0  </span><br>
		<span style="margin-left: 23px;">订单红包＝订单金额*{{env('RECHARGE_FEE')*100}}%*红包比例  ; 红包比例＝平台占比＋代理商占比</span>
	    <table border="1">
	    	<tr>
	    		<td>平台占比</td>
	    		<td>代理商占比</td>
	    		<td>红包比例</td>
	    		<td>使用期限</td>
	    		<td>操作</td>
	    	</tr>
	    	<tr>
	    		<td>{{$hqratio}}%</td>
	    		<td>{{$agentratio}}%</td>
	    		<td>{{$ratio}}%</td>
	    		<td>{{$validdays}}</td>
	    		<td><s class="co_violet red_intercalate" onclick="get_ratio('{{$id}}', '{{$name}}', '{{$agentratio}}', '{{$ratio}}')">编辑</s></td>
	    	</tr>
	    </table>
	</div>
	<a class="historic_records" href="/mobile/mycenter/redenvelope/history?cityid={{$cityid}}">历史设置记录>></a>
	<!-- 暂不开放 -->
	<!--
	<div class="details2">
		<div class="red_envelope_title">
			<p>
				<span style="border: 1px solid #9955c6;color: #9955c6;">本地运营红包</span>
				<span>全国运营红包</span>
			</p>
		</div>
		<ul>
			<li>
				<span style="margin-left: 23px;">订单红包为无使用金额与品类限制的红包，订单红包金额低于1.0时不发给用户，最低为1.0  </span><br>
				<span style="margin-left: 23px;">订单红包＝订单金额*{{env('RECHARGE_FEE')*100}}%*红包比例  ; 红包比例＝平台占比＋代理商占比</span>
				<table class="red_envelope_count">
					<tr>
						<td>50000.0</td>
						<td>30000.0</td>
						<td>901.0</td>
						<td>20901.0</td>
					</tr>
					<tr>
						<td>本地运营红包预充值</td>
						<td>已投放的本地运营红包</td>
						<td>退回的本地运营红包</td>
						<td>本地运营红包余额</td>
					</tr>
				</table>
				<div class="oh">
					<p class="title fl">红包活动列表</p>
					<p class="set_up fr"><a style="width:100%;color: #fff;" href="/console/system/red/active/set">创建红包活动</a></p>
				</div>
				<table class="red_envelope_list" border="1">
					<thead>
						<tr>
							<td>序号</td>
							<td>活动名称</td>
							<td>投放位置</td>
							<td>投放用户</td>
							<td>红包总金额</td>
							<td>投放时间</td>
							<td>状态</td>
							<td>操作</td>
						</tr>
					</thead>
					<tbody>
						<tr>
							<td>1</td>
							<td>123开始</td>
							<td>首页</td>
							<td>0充值用户</td>
							<td>8000</td>
							<td>2017-02-25至2017-03-15</td>
							<td>已开始</td>
							<td>
								<a href="#" class="co_violet">查看</a>
								<a href="#" class="co_orange">停止</a>
							</td>
						</tr>
					</tbody>
				</table>
			</li>
			<li hidden>
				<p class="title">红包活动列表</p>
				<table class="red_envelope_list" border="1">
					<thead>
						<tr>
							<td>序号</td>
							<td>活动名称</td>
							<td>投放位置</td>
							<td>投放用户</td>
							<td>红包总金额</td>
							<td>投放时间</td>
							<td>状态</td>
							<td>操作</td>
						</tr>
					</thead>
					<tbody>
						<tr>
							<td>1</td>
							<td>123开始</td>
							<td>首页</td>
							<td>0充值用户</td>
							<td>8000</td>
							<td>2017-02-25至2017-03-15</td>
							<td>已开始</td>
							<td>
								<a href="/console/system/red/active/details">查看</a>
							</td>
						</tr>
					</tbody>
				</table>
			</li>
		</ul>
	</div>
	-->

	<!-- 代理商红包比例设定 -->
	<form action="" method="" id="red_envelope_form">
		<nav class="red_intercalate_value">
			<p class="title">红包比例</p>
			<img class="fr red_intercalate_close" src="{{env('IMAGE_DOMAIN')}}images/close_p.png" alt="">
			<input type="hidden" name="cityid" value="{{$id}}" />
			<p class="content city co_gray">
				<span>南昌红包占比:</span>
				<span>0%</span>
			</p>
			<p class="content hqratio">
				<span>平台占比:</span>
				<span>30%*{{$hqratio/30*100}}%</span>
			</p>
			<p class="content agentratio">
				<span>代理商占比: 70%*</span>
				<input style="width: 110px;" type="text" name="red_agentratio" value="{{$agentratio/70*100}}" placeholder="请填入0~100数字">%
			</p>
			<p class="content date">
				<span>使用期限:</span>
				<input style="margin-right: 10px;width: 50px;" type="text" name="validdays" value="{{$validdays}}">天
			</p>
			<!-- <p class="content">
				<span>红包方式:</span>
				<select name="redenvelopepath" id="red_way" style="border: 1px solid #000;height: 25px;">
					<option value="">拼手气红包－用户分享多人领取</option>
					<option value="">普通红包－仅用户本人领取</option>
				</select>
			</p> -->
			<p class="content message co_orange" hidden></p>
			<p style="overflow: hidden;margin: 20px 0;">
				<input class="fl" id="red_intercalate_cancel" type="button" name="" value="取消">
				<input class="fr" id="red_intercalate_sure" type="button" name="" value="确定">
			</p>
		</nav>
	</form>
		
</section>
@endsection

@section('scriptResources')
    @parent
    <script>
    	$(".red_intercalate").click(function(){
    		$(".red_intercalate_value").show();
    	})
    	$(".red_intercalate_close").click(function(){
    		$(".red_intercalate_value").hide();
    	})
    	$("#red_intercalate_cancel").click(function(){
    		$(".red_intercalate_value").hide();
    	})
    	//本地、全国红包切换
    	$(".red_envelope_title p span").click(function(){
    		var i = $(this).index();
    		$(".red_envelope_title p span").eq(i).css({"border": "1px solid #9955c6","color": "#9955c6"}).siblings().css({"border": "1px solid #333","color": "#000"});
    		$('.details2 ul li').eq(i).show().siblings().hide();
    	})
    	//获取红包比例
    	function get_ratio(id, name,agentratio,ratio) {
    	    $("input[name='agentcityid']").val(id);
    	    $(".city span").eq(0).html(name+"订单红包占比：");
    	    $(".city span").eq(1).html(ratio+"%");
    	     redHqratioBlur(agentratio)
    	}
    	function redHqratioBlur(agentratio){
    		$("input[name='red_agentratio']").blur(function(){
    	    	if($("input[name='red_agentratio']").val() == ""){
    	    		$(".message").show();
    	    		$(".message").html("请输入代理商占比");
    	    	}else if($("input[name='red_agentratio']").val()<0||$("input[name='red_agentratio']").val()>100){
    	    		$(".message").show();
    	    		$(".message").html("代理商占比不能少于0%或大于100%");
    	    	}else{
    	    		$(".message").hide();
    	    		var new_hqratio = 30*$("input[name='red_agentratio']").val()/100;
	    	    	var order_red_ratio = Number(agentratio) + (30*$("input[name='red_agentratio']").val()/100);
					$(".city span").eq(1).html(order_red_ratio+"%");
					$("input[name='hqratio']").val(new_hqratio);
    	    	}
    	    })
    	}
    	$("#red_intercalate_sure").click(function(){
    		if($("input[name='red_agentratio']").val() == ""){
	    		$(".message").show();
	    		$(".message").html("请输入代理商占比");
	    	}else if($("input[name='red_agentratio']").val()<0||$("input[name='red_agentratio']").val()>100){
	    		$(".message").show();
	    		$(".message").html("代理商占比不能少于0%或大于100%");
	    	}else{
	    		$(".message").hide();
	    		$.ajax({
	                url: '/console/user/red/envelope/agentratio/update',
	                type: 'post',
	                data:$("#red_envelope_form").serialize(),
	                dataType:'json',
	                success:function(data){
	                    if(data.status == 'success') {
	                         $(".red_intercalate_value").hide();
	                         window.location.reload();
	                    } else {
	                        alert(data.message);
	                    }
	                }
	            })
	    	}
        })
    </script>
@endsection